import { createApp } from 'vue'
import App from './App.vue'
import './styles/tailwindcss.css'
import './style.css'
// import "aieditor/dist/style.css";
import '@wangeditor-next/editor/dist/css/style.css' // 引入 css


import router from './router/index'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import 'element-plus/dist/index.css'
import { VueQueryPlugin, QueryClient } from '@tanstack/vue-query'
import websocket from '@/utils/websocket'

const pinia = createPinia()

export const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      refetchOnWindowFocus: false,
      retry: 0,
      // staleTime: 1000 * 60 * 5,
      // cacheTime: 1000 * 60 * 30,
    },
  },
})

const app = createApp(App)
app.use(ElementPlus, {
  locale: zhCn,
})
app.use(pinia)
app.use(router)
app.use(VueQueryPlugin, { queryClient })

window.$router = router // 如果你需要全局访问

app.mount('#app')

// 自动恢复 WebSocket 连接（确保 Pinia 已激活）
const token = localStorage.getItem('token')
if (token) {
  websocket.initConnect()
}